﻿//"The contents of this file are subject to the Mozilla Public License
//Version 1.1 (the "License"); you may not use this file except in
//compliance with the License. You may obtain a copy of the License at
//http://www.mozilla.org/MPL/

//Software distributed under the License is distributed on an "AS IS"
//basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
//License for the specific language governing rights and limitations
//under the License.

//The Original Code is TSharp.

//The Initial Developer of the Original Code is Mar3ek (http://mar3ek.wordpress.com).
//Portions created by Mar3ek are Copyright (C) 2010
//Mar3ek (http://mar3ek.wordpress.com). All Rights Reserved.

//Contributor(s): ______________________________________.

//Alternatively, the contents of this file may be used under the terms
//of the _____ license (the  "[___] License"), in which case the
//provisions of [______] License are applicable instead of those
//above.  If you wish to allow use of your version of this file only
//under the terms of the [____] License and not to allow others to use
//your version of this file under the MPL, indicate your decision by
//deleting  the provisions above and replace  them with the notice and
//other provisions required by the [___] License.  If you do not delete
//the provisions above, a recipient may use your version of this file
//under either the MPL or the [___] License."

using System;
using System.Runtime.Serialization;
using System.Security.Permissions;

namespace TSharp
{
    ///<summary>
    /// Class represnting a Twitter user
    ///</summary>
    [Serializable]
    public class TwitterUser : ISerializable
    {
        private readonly string _description;
        private readonly long _followersCount;
        private readonly bool _following;
        private readonly string _location;
        private readonly Uri _profileImageUrl;
        private readonly string _screenName;
        private readonly long _statusesCount;
        private readonly string _url;
        private readonly ulong _userId;
        private readonly string _userName;
        private readonly ulong _listedCount;
        private readonly bool _showAllInlineMedia;
        private readonly bool _followRequestSent;

        #region Properties

        ///<summary>
        /// ID of the user
        ///</summary>
        public ulong UserId
        {
            get { return _userId; }
        }

        ///<summary>
        /// Name of the user
        ///</summary>
        public string UserName
        {
            get { return _userName; }
        }

        ///<summary>
        /// Screen name of the user
        ///</summary>
        public string ScreenName
        {
            get { return _screenName; }
        }

        ///<summary>
        /// Location of the user
        ///</summary>
        public string Location
        {
            get { return _location; }
        }

        ///<summary>
        /// Description of the user
        ///</summary>
        public string Description
        {
            get { return _description; }
        }

        ///<summary>
        /// URL of the user's profile image
        ///</summary>
        public Uri ProfileImageUrl
        {
            get { return _profileImageUrl; }
        }

        ///<summary>
        /// URL of the user's Twitter page
        ///</summary>
        public string Url
        {
            get { return _url; }
        }

        ///<summary>
        /// Number of user's followers
        ///</summary>
        public long FollowersCount
        {
            get { return _followersCount; }
        }

        ///<summary>
        /// Number of user's statuses
        ///</summary>
        public long StatusesCount
        {
            get { return _statusesCount; }
        }

        ///<summary>
        /// Specifies whether the authenticating user follows this user
        ///</summary>
        [Obsolete("The attribute will be removed in version 2.")]
        public bool Following
        {
            get { return _following; }
        }

        /// <summary>
        /// Gets the number of times this user has been added to a list
        /// </summary>
        public ulong ListedCount
        {
            get { return _listedCount; }
        }

        // TODO: Find out what does this mean:
        /// <summary>
        /// ?
        /// </summary>
        public bool ShowAllInlineMedia
        {
            get { return _showAllInlineMedia; }
        }

        /// <summary>
        /// Specifies whether the authenticating user has sent a follow request to this user
        /// </summary>
        public bool FollowRequestSent
        {
            get { return _followRequestSent; }
        }

        #endregion

        ///<summary>
        /// Creates a new instance of the TwitterUser class
        ///</summary>
        ///<param name="userId">ID of the user</param>
        ///<param name="userName">Name of the user</param>
        ///<param name="screenName">Screen name of the user</param>
        ///<param name="location">Location of the user</param>
        ///<param name="description">Description of the user</param>
        ///<param name="profileImageUrl">URL of the user's profile image</param>
        ///<param name="url">URL of the user's Twitter page</param>
        ///<param name="followersCount">Number of user's followers</param>
        ///<param name="statusesCount">Number of user's statuses</param>
        ///<param name="following">Whether the authenticating user follows this user</param>
        ///<param name="listedCount">The number of times this user has been added to a list</param>
        ///<param name="showAllInlineMedia">?</param>
        ///<param name="followRequestSent">Whether the authenticating user has sent a follow request to this user</param>
        public TwitterUser(ulong userId, string userName, string screenName, string location, string description,
                           Uri profileImageUrl, string url, long followersCount, long statusesCount, bool following, ulong listedCount, bool showAllInlineMedia, bool followRequestSent)
        {
            _userId = userId;
            _following = following;
            _userName = userName;
            _screenName = screenName;
            _location = location;
            _description = description;
            _profileImageUrl = profileImageUrl;
            _url = url;
            _followersCount = followersCount;
            _statusesCount = statusesCount;
            _listedCount = listedCount;
            _showAllInlineMedia = showAllInlineMedia;
            _followRequestSent = followRequestSent;
        }

        /// <exception cref="ArgumentNullException"><paramref name="info" /> is <c>null</c>.</exception>
        protected TwitterUser(SerializationInfo info, StreamingContext context)
        {
            if (info == null) throw new ArgumentNullException("info");
            _userId = (ulong) info.GetValue("userid", typeof (ulong));
            _following = (bool) info.GetValue("following", typeof (bool));
            _userName = (string) info.GetValue("userName", typeof (string));
            _screenName = (string) info.GetValue("screenname", typeof (string));
            _location = (string) info.GetValue("location", typeof (string));
            _description = (string) info.GetValue("description", typeof (string));
            _profileImageUrl = (Uri) info.GetValue("profileimageurl", typeof (Uri));
            _url = (string) info.GetValue("url", typeof (string));
            _followersCount = (long) info.GetValue("userid", typeof (long));
            _statusesCount = (long) info.GetValue("userid", typeof (long));
            _listedCount = (ulong) info.GetValue("listedcount", typeof (ulong));
            _showAllInlineMedia = (bool) info.GetValue("showallinline", typeof (bool));
            _followRequestSent = (bool) info.GetValue("followrequestsent", typeof (bool));
        }

        #region ISerializable Members

        /// <exception cref="ArgumentNullException"><paramref name="info" /> is <c>null</c>.</exception>
        [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
        public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            if (info == null) throw new ArgumentNullException("info");
            info.AddValue("userid", _userId);
            info.AddValue("following", _following);
            info.AddValue("userName", _userName);
            info.AddValue("screenname", _screenName);
            info.AddValue("location", _location);
            info.AddValue("description", _description);
            info.AddValue("profileimageurl", _profileImageUrl);
            info.AddValue("url", _url);
            info.AddValue("followerscount", _followersCount);
            info.AddValue("statusescount", _statusesCount);
            info.AddValue("listedcount", _listedCount);
            info.AddValue("showallinline", _showAllInlineMedia);
            info.AddValue("followrequestsent", _followRequestSent);
        }

        #endregion
    }
}